#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e5+10;

int f[2][MAXN],n,siz[2],cur,T;

struct treasure{
	int t,q;
	bool operator < (const treasure &b)const{
		return t < b.t;
	}
}t[MAXN];

int main (){
	scanf("%d %d",&n,&T);
	for(int i = 1;i <= n;i++) scanf("%d %d",&t[i].t,&t[i].q);
	sort(t+1,t+n+1);
	cur = 1;
	for(int i = 1,o = 1;i <= T;i++,o^=1){
		while(cur <= n && t[cur].t == i) f[o][++siz[o]] = t[cur++].q;
		sort(f[o]+1,f[o]+siz[o]+1,greater<int>());
		if(i == T){
			printf("%d\n",f[o][1]);
			return 0;
		}
		if(siz[o] & 1) f[o][++siz[o]] = 0;
		siz[o^1] = 0;
		for(int j = 1;j <= siz[o];j+=2)
			f[o^1][++siz[o^1]] = f[o][j] + f[o][j+1];
	}
}
